@model ShoppingCartViewModel
@using OrchardCore.Commerce.Abstractions
@using Money
<zone name="Header">
    <header class="masthead">
        <div class="container">
            <div class="intro-text">
                <div class="intro-lead-in"></div>
                <div class="intro-heading text-uppercase">@T["Your cart"]</div>
            </div>
        </div>
    </header>
</zone>
<section id="shopping-cart">
@if (Model.Lines != null && Model.Lines.Any())
{
    <div class="container">
        <div class="d-none d-sm-flex row border-bottom mt-3 pb-2 font-weight-bold">
            <div class="col-xs-12 col-sm-1">@T["Quantity"]</div>
            <div class="col-xs-12 col-sm-9">@T["Product"]</div>
            <div class="col-xs-12 col-sm-1">@T["Price"]</div>
            <div class="col-xs-12 col-sm-1">@T["Action"]</div>
        </div>
        @{
            int line = 0;
        }
        @foreach (ShoppingCartLineViewModel item in Model.Lines)
        {
            <div class="row border-bottom mt-3 pb-2">
                <div class="col-xs-12 col-sm-1">
                    @{
                        int i = 0;
                        var name = $"cart.lines[{line++}]";
                    }
                    <input form="shopping-cart-update" type="number" min="0" name="@(name).Quantity" value="@item.Quantity" class="form-control" />
                    <input form="shopping-cart-update" type="hidden" name="@(name).ProductSku" value="@item.ProductSku" />
                    @foreach (IProductAttributeValue attr in item.Attributes.Select(attr => attr.Value).Where(val => val.UntypedValue != null))
                    {
                        <shape Type="@attr.GetType().Name" alternate="@(attr.GetType().Name)_hidden" form="shopping-cart-update" prop-index="@(i++)" prop-attributeValue="@attr" prop-namePrefix="@name" />
                    }
                </div>
                <div class="col-xs-12 col-sm-9">
                    <a href="@item.ProductUrl">@item.ProductName</a>
                    @if (item.Attributes != null)
                    {
                        <ul class="cart-product-attributes list-inline">
                            @foreach (IProductAttributeValue attr in item.Attributes.Select(attr => attr.Value).Where(val => val.UntypedValue != null))
                            {
                                <shape tag="li" Type="@attr.GetType().Name" prop-attribute="@attr" prop-label="@attr.Label" />
                            }
                        </ul>
                    }
                </div>
                <div class="col-xs-12 col-sm-1">@item.UnitPrice</div>
                <div class="col-xs-12 col-sm-1">
                    @{
                        i = 0;
                    }
                    <form asp-action="RemoveItem" asp-controller="ShoppingCart" asp-area="OrchardCore.Commerce">
                        <input type="hidden" name="line.ProductSku" value="@item.ProductSku" />
                        @foreach (IProductAttributeValue attr in item.Attributes.Select(attr => attr.Value).Where(val => val.UntypedValue != null))
                        {
                            <shape Type="@attr.GetType().Name" alternate="@(attr.GetType().Name)_hidden" prop-index="@(i++)" prop-attributeValue="@attr" />
                        }
                        <button type="submit" class="btn btn-primary">@T["Remove"]</button>
                    </form>
                </div>
            </div>
        }
        <div class="row mt-3 mb-3 pb-2">
            <div class="col-xs-12 col-sm-10 font-weight-bold">@T["Total"]</div>
            <div class="col-xs-12 col-sm-1">
                @foreach (Amount total in Model.Totals)
                {
                    <div>@total</div>
                }
            </div>
            <div class="col-xs-12 col-sm-1">
                <form asp-action="Update" asp-controller="ShoppingCart" asp-area="OrchardCore.Commerce" id="shopping-cart-update">
                    <button type="submit" class="btn btn-primary">@T["Update"]</button>
                </form>
            </div>
        </div>
    </div>
}
else
{
    <p>@T["Your shopping cart is empty."]</p>
}
</section>
